package com.cnplan.core;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

public class ThreadPoolUtils {
    private static final ExecutorService threadPool;

    static {
        int corePoolSize = 7;
        int maxPoolSize = 100;
        long keepAliveTime = 30;
        TimeUnit keepAliveTimeUnit = TimeUnit.MINUTES;
        int queSize = 50;
        ThreadFactory threadFactory = new ThreadFactoryBuilder()
                .setNameFormat("ThreadPoolUtils")
                .build();

        threadPool = new ThreadPoolExecutor(corePoolSize, maxPoolSize,
                keepAliveTime, keepAliveTimeUnit, new ArrayBlockingQueue(queSize)
                , threadFactory);
    }


    /**
     * 获取线程池
     * @return 线程池
     */
    public static ExecutorService getThreadPool() {
        return threadPool;
    }


}